<template>
	<view class="coupon_index">
		<mescroll-body ref="mescrollRef" @up="upCallback" @down="downCallback">
			<view class="coupon_items" v-for="(v,k) in list" :key="k" @click="$nav('/pages/store/index?id='+v.store_id)">
				<coupon types="true" :item="{seller_name:v.nickname,money:v.money,end_time:v.created_at,title:(v.use_money>0?('满'+v.use_money+'减'+v.money):'')}"></coupon>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import coupon from '@/components/coupon.vue'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {coupon},
		data() {
			return {
				params:{
					page:1,
					per_page:10,
				},
				list:[],
			};
		},
		onLoad() {
			
		},
		methods:{
			upCallback(page){
				this.params.page = page.num; // 页码, 默认从1开始
				this.params.per_page = page.size; // 页长, 默认每页10条
				
				this.$http(this.$api.coupons,this.params).then(res=>{
					if(res.code == 200){
						if(this.params.page == 1){
							this.list = [];
						}
						this.list = this.list.concat(res.data.data||res.data); //追加新数据
						this.mescroll.endBySize(this.params.per_page, res.data.total); 
						if(res.data.total<8){
							this.mescroll.endUpScroll(false)
						}
						if(res.data.total==0){
							this.mescroll.showEmpty();
						}
					}
				})
			},
			downCallback(){
				this.mescroll.resetUpScroll();
			}
		}
	}
</script>

<style lang="scss">
.coupon_index{
	padding: 20rpx 0;
	.coupon_items{
		padding: 20rpx 20rpx;
		background-color: #fff;
	}
}
</style>
